Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
How to fix "script.js:5 Uncaught TypeError: ..." JavaScript error

I'm working on a little project, and I came across the following JavaScript error:

script.js:5 Uncaught TypeError: Cannot set properties of null (setting 'onkeyup')
at script.js:5:18

Here is the HTML & JavaScript code I used:

window.addEventListener("load", () => {
  var filter = document.getElementById("the-filter"),
      list = document.querySelectorAll("#the-list li");
      
  filter.onkeyup = () => {
    let search = filter.value.toLowerCase();
 
    for (let i of list) {
      let item = i.innerHTML.toLowerCase();
      if (item.indexOf(search) == -1) { i.classList.add("hide"); }
      else { i.classList.remove("hide"); }
    }
  };
});
#the-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

#the-list a {
    text-decoration: none;
}

#the-list li {
  padding: 10px;
  border-bottom: 2px solid #ddd;
}

#the-list li:hover { 
    background: #ddd;
    cursor: pointer;
}
#the-list li.hide { 
    display: none;
}
<input type="text" id="the-filter" placeholder="Search The Marketplace..."/>
            
                <ul id="the-list">
                    <a href="a_link.htm"><li>Item</li></a>
          <a href="a_link.htm"><li>Item1</li></a>
          <a href="a_link.htm"><li>Item2</li></a>
          <a href="a_link.htm"><li>Item3</li></a>
                </ul>

I understand what is causing this issue, but I'm not sure how to fix it.. And it all works just fine when opened in the browser, except that it's displaying this error.

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Looks like the input DOM was not ready

try

window.addEventListener('DOMContentLoaded', (event) => {
    // your code
    // DOM ready
});
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda